package com.cqc.other.juc.producerConsumer.blockingQueue.demo2;

import java.util.concurrent.*;


public class Container {
    /**
     * 初始化阻塞队列
     */
//    private final BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(10);
//    private final BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
    private final BlockingQueue<Integer> queue = new PriorityBlockingQueue<>();


    public void add(Integer value) {
        try {
            queue.put(value);
            System.out.println("生产者，value:" + value + "，" + Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void get() {
        try {
            Integer value = queue.take();
            System.out.println("消费者，value:" + value + "，" + Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
